package com.huawei.appgallery.foundation.ui.framework.fragment.widget;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.ListAdapter;
import androidx.annotation.NonNull;
import com.huawei.appgallery.foundation.ui.framework.widget.PullUpListView;
import o.dky.j;

public class SwitchTabListView extends PullUpListView {
    private SwitchTabHintView ʻ;
    private int ʼ;
    private int ʽ;
    private int ˊॱ;
    private boolean ˋॱ;
    private int ˏॱ;
    private boolean ͺ;
    private boolean ॱˊ = false;
    private String ॱˋ;
    private SwitchTabHintView ॱॱ;
    private int ᐝ;
    private String ᐝॱ;

    public SwitchTabListView(Context context) {
        super(context);
    }

    public SwitchTabListView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
    }

    public SwitchTabListView(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
    }

    public void ˊ(@NonNull Context context) {
        super.ˊ(context);
        setOverScrollMode(2);
    }

    public void setTabInfo(boolean z, boolean z2, String str, String str2) {
        this.ˋॱ = z;
        this.ͺ = z2;
        this.ᐝॱ = str;
        this.ॱˋ = str2;
    }

    public void setAdapter(ListAdapter listAdapter) {
        super.setAdapter(listAdapter);
        ˋ(getContext());
        ˏ(getContext());
    }

    private void ˋ(Context context) {
        if (this.ॱॱ == null) {
            this.ॱॱ = new SwitchTabHintView(context);
            this.ॱॱ.setDirection(j.ˈ);
            this.ॱॱ.setImgRotation(180);
            if (!TextUtils.isEmpty(this.ᐝॱ) && ˎ(context)) {
                this.ॱॱ.setNextTab(this.ᐝॱ);
            }
            addHeaderView(this.ॱॱ);
        }
        this.ॱॱ.measure(0, 0);
        this.ʽ = this.ॱॱ.getMeasuredHeight();
        this.ॱॱ.setPadding(0, -this.ʽ, 0, 0);
    }

    private void ˏ(Context context) {
        if (this.ʻ == null) {
            this.ʻ = new SwitchTabHintView(context);
            this.ʻ.setDirection(j.ˊᐝ);
            this.ʻ.setImgRotation(0);
            if (!TextUtils.isEmpty(this.ॱˋ) && ˎ(context)) {
                this.ʻ.setNextTab(this.ॱˋ);
            }
            addFooterView(this.ʻ);
        }
        this.ʻ.ˋ();
    }

    public void ॱ() {
        if (this.ʻ != null) {
            this.ʻ.ˋ();
        }
    }

    public void y_() {
        if (!ˈ()) {
            this.ʻ.ˎ();
        }
    }

    public boolean onTouchEvent(MotionEvent motionEvent) {
        switch (motionEvent.getAction()) {
            case 0:
                this.ʼ = (int) motionEvent.getRawY();
                break;
            case 1:
                ʽॱ();
                ᐝॱ();
                this.ʼ = 0;
                this.ॱˊ = false;
                break;
            case 2:
                ˎ(motionEvent);
                ॱ(motionEvent);
                break;
            default:
                this.ʼ = 0;
                this.ॱˊ = false;
                break;
        }
        if (this.ॱˊ) {
            return true;
        }
        return super.onTouchEvent(motionEvent);
    }

    public boolean performClick() {
        return super.performClick();
    }

    private void ᐝॱ() {
        if (!this.ˏ.hasMore() && getLastVisiblePosition() == getCount() - 1 && !ˈ()) {
            if (this.ˎ != null && ((double) (-this.ˏॱ)) > ((double) this.ʽ) * 0.8d) {
                this.ˎ.ˊʼ();
            }
            this.ʻ.setPadding(0, 0, 0, 0);
        }
    }

    private void ʽॱ() {
        if (getFirstVisiblePosition() == 0 && !ʼॱ()) {
            if (this.ˎ != null && this.ˊॱ > this.ʽ) {
                this.ˎ.ʿॱ();
            }
            this.ॱॱ.setPadding(0, -this.ʽ, 0, 0);
        }
    }

    private void ॱ(MotionEvent motionEvent) {
        if (ॱᐝ() && !this.ˏ.hasMore() && !ˈ()) {
            int rawY = (int) motionEvent.getRawY();
            if (this.ʼ == 0) {
                this.ʼ = rawY;
            }
            this.ˏॱ = (rawY - this.ʼ) / 3;
            if (this.ˏॱ < 0) {
                this.ʻ.setPadding(0, 0, 0, -this.ˏॱ);
            }
        }
    }

    private void ˎ(MotionEvent motionEvent) {
        if (ʻॱ() && !ʼॱ()) {
            int rawY = (int) motionEvent.getRawY();
            if (this.ʼ == 0) {
                this.ʼ = rawY;
            }
            this.ˊॱ = (rawY - this.ʼ) / 3;
            if (this.ˊॱ > 0) {
                this.ॱˊ = true;
                this.ᐝ = (-this.ʽ) + this.ˊॱ;
                this.ॱॱ.setPadding(0, this.ᐝ, 0, 0);
            }
        }
    }

    private boolean ʼॱ() {
        return this.ˋॱ;
    }

    private boolean ˈ() {
        return this.ͺ;
    }

    public boolean ˎ(Context context) {
        if (context.getResources().getConfiguration().locale.getLanguage().endsWith("zh")) {
            return true;
        }
        return false;
    }
}
